package day20.zhiyou100;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Demo01 {

    static int i = 0;

    public static void main(String[] args) {
        ExecutorService executorService = Executors.newCachedThreadPool();
        tEST1(executorService);
    }
    private final static Lock lock = new ReentrantLock();

    private AtomicInteger count=new AtomicInteger();//用乐观锁来用来记录浏览的人次

    public static void tEST1(ExecutorService executorService){
        for (int k = 0; k < 100; k++) {
            executorService.submit(new Runnable() {
                @Override
                public void run() {
                    lock.lock();
                    i++;
                    System.out.println(Thread.currentThread().getName()+"count========>"+i);
                    lock.unlock();
                }
            });
        }
        System.out.println(i);
    }
}